const express = require( 'express' );
const router = express.Router();

let logger = require( "../../../../utils/utils.logger" );
const tools = require( "../../../../utils/utils.tools" );
const db = require( "../../../../models" );

const sequelize = db.sequelize;
const {  Op } = require( "sequelize" );
const experience = require( "../../../../controllers/experience.controller" );
/**
 * 获取个人经历所有数据
 * @route GET /api/public/personal/experience/list
 * @group 获取个人经历 - list
 * @returns {object} 200 - 请求返回正确
 * @returns {object} 500 - 请求返回错误
 * @returns {Error}  default - Unexpected error
 */

router.get( "/list", function ( req, res ) {
    const pm = {
        limit: 1000,
        offset: 1,
        params: {
            show:1
        },
        sort: {
            prop: "start_time",
            order: "desc"
        }
    };
    let clientIp = req.headers[ 'x-forwarded-for' ] ||
        req.connection.remoteAddress ||
        req.socket.remoteAddress ||
        req.connection.socket.remoteAddress;
     logger.info( `【IP】${clientIp}【获取资历数据】 ` )
    experience.getAllList( pm, ( data, err ) => {
        if ( err ) return res.sendResultAto( null, 401, err )
   
        let arr = data.data.data
       let  resArr = []
        for ( let i = 0; i < arr.length; i++ ) { 
            arr[i].start_time = tools.timestampToTime( arr[i].start_time, 'YM' )
            arr[ i ].end_time ? arr[ i ].end_time = tools.timestampToTime( arr[ i ].end_time, 'YM' ) : ''
            arr[ i ].createdAt = tools.timestampToTime( arr[ i ].createdAt, 'YMDHM' )
            arr[i].updatedAt = tools.timestampToTime( arr[i].updatedAt, 'YMDHM' )
            resArr.push( {
                start_time: arr[ i ].start_time,
                end_time: arr[i].end_time,
                unit: arr[i].unit,
                position: arr[i].position,
                type: arr[ i ].type
            } )
        }
        res.sendResultAto( resArr, 200, '获取数据成功' )
    } )


} );
module.exports = router;
